import { _decorator, Component, Node, instantiate, Label, game, AudioSource, Prefab } from 'cc';
import { mb_base_cp,mb_audio_const } from 'db://magic-book/src';
import { audio_playing_template } from './audio_playing_template';
const { ccclass, property } = _decorator;

@ccclass('audio_layout_playing')
export class audio_layout_playing extends mb_base_cp {

    @property(Prefab)
    playing_template: Prefab = null;

    onLoad() {
        game.on(mb_audio_const.event_play_audio, this.on_play_audio, this);
    }

    on_play_audio(source: AudioSource, is_music: boolean) {
        const node = instantiate(this.playing_template);
        this.node.addChild(node);
        node.getComponent(audio_playing_template).init(source, is_music);
    }


}

